define(["jquery","bbcare"],function($,$bb){
    var servers = {};
    var URL = $bb.baseUrl("followup");
    /*
    * 获取问卷：
    * */
    servers.getQuestions = function(params,callback,otherParams){
        $bb.ajax({
            url: URL + "followup/service/patient/evaluation/getAllPostion",
            data:JSON.stringify({
                data :{
                    "examinationPaperName":params.type,
                    "userId":params.userId
                }
            }),
            success: function(data){
                callback(data);
            }
        });
    };
    /*
    * 处理问卷：
    * */
    servers.dealQuestion = function(lesData){
        var totalQuestions = [];
        for(var i = 0;i< lesData.length ; i++){//大层级：
            for(var j = 0;j< lesData[i].questions.length;j++){//每一个大层级的题目：
                lesData[i].questions[j].itemTitle = lesData[i].title;
                lesData[i].questions[j].initId = lesData[i].initId;
                //获取每个小问卷的题目；
                var ques = lesData[i].questions[j].questions;
                for(var k = 0;k<ques.length;k++){  //每一个题目的小选项：
                    ques[k].fuId = lesData[i].questions[j].id;
                    ques[k].title = lesData[i].questions[j].title;
                }
                totalQuestions.push(lesData[i].questions[j]);
            }
        }
        return totalQuestions;
    };
    servers.dealQuestions_les = function(totalQuestions){
        var questions = {};
        for(var i  = 0;i<totalQuestions.length;i++ ){
            var item = totalQuestions[i].id;
            questions[item] = totalQuestions[i];
            /*totalQuestions[i].questions[k].extra = [{"num":1},{"num":2}];//备注：*/
        }
        return questions;
    };
    /*
     * 问卷答案处理：
     * */
    servers.lesAnswerDeal = function(question,nextId,scoreObj){
        for(var i = 0;i<question[nextId].questions.length;i++){
            var fuId = question[nextId].questions[i].fuId;
            var childId = question[nextId].questions[i].id;
            if(childId != 5){
                if(scoreObj["ques"][fuId+"."+childId]){
                    question[nextId].questions[i].value = question[nextId].questions[i].option[scoreObj["ques"][fuId+"."+childId]];
                }
            }else{
                if(childId == 5){
                    if(question[nextId].questions[i].name=="5.请填写该事件发生的年月:"){
                        var times = [];
                        if(scoreObj["ques"][fuId+"."+childId]){
                            times.push(scoreObj["ques"][fuId+"."+childId]);
                            if(scoreObj["manyTimes"][fuId+"."+childId]){
                                for(var item in scoreObj["manyTimes"][fuId+"."+childId]){
                                    times.push(scoreObj["manyTimes"][fuId+"."+childId][item].value);
                                }
                            }
                            question[nextId].questions[i].value = times.join(";");
                        }
                    }else{
                        if(scoreObj["ques"][fuId+"."+childId]){
                            var times2 = JSON.parse(scoreObj["ques"][fuId+"."+childId])//{"startTime":"2017-12-03","endTime":"至今"}
                            question[nextId].questions[i].value = "开始时间："+times2.startTime+";结束时间："+times2.endTime;
                        }
                    }
                }
            }
        }
    };
    return servers;
});